<?php

/**
 * Controller_teaching
 * 教研计划
 */

class Controller_teachingtotal extends MyApp {

	public function __construct()
	{

		parent::__construct();

		$this->model->log   	= YOU::loadModel('log');

	}
    /** 首页 **/
    public function actionIndex()
    {
			
    }

    /** 管理栏目列表 **/

    public function actionTeachingTotalList ()
    {  
    	
    	// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		
    	// 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_manage` WHERE `manage_type`='2'");
		
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);
        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){	
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
		// 2=教研计划
        $manage_list = $this->db->fetchAll("SELECT * FROM `tbl_manage` WHERE `manage_type`='2' ORDER BY manage_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		foreach($manage_list as $key=>$value){
			$staff_data = $this->db->fetchRow("SELECT `staff_name` FROM `tbl_staff` WHERE staff_id={$value['staff_id']}");
			$manage_list[$key]['staff_name'] = $staff_data['staff_name'];
		}
		// 搜索
		if($_POST){

			$manage_title     		= $this->post->manage_title;
			$start_time     		= $this->post->start_time;
			$end_time     			= $this->post->end_time;

			// 标题搜索
			if(!empty($manage_title)){
				
				$manage_list = $this->db->fetchAll("SELECT * FROM `tbl_manage` WHERE manage_title LIKE '%{$manage_title}%' AND `manage_type`='2'");

			}
			
			// 时间段搜索
			if(!empty($start_time) && !empty($end_time) ){
				
				$manage_list = $this->db->fetchAll("SELECT * FROM `tbl_manage` WHERE `manage_type`='2' AND create_time>='{$start_time}' AND create_time<='{$end_time}'");
	
			}

		}

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("manage_list", $manage_list);
        $this->tpl->display('teaching/total.list.tpl.php');
    }
   /** 教研总结添加 **/
    public function actionTeachingTotalAdd()
    {        
    	// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		

        if ($_POST){ 

            $manage_title     	    = $this->post->manage_title;
            $manage_content   		= $this->post->manage_content;             

            // 写入数据库
            $info = array( 
				
			"manage_title"  	    => $manage_title,
            "manage_content"       	=> $manage_content,
			// 教研总结 =2
			"manage_type"       	=> 2,	
            "status"                => 1,
            "create_time"           => date("Y-m-d H:i:s"),
            "update_time"           => "0000-00-00 00:00:00",  

			 );

          $this->db->do_insert("tbl_manage", $info);
          Helper_Client::location("添加成功", "index.php?a=teachingtotal.teachingTotallist");

         }
          
         $this->tpl->display("teaching/total.add.tpl.php");
    }
    /** 教研计划修改 **/
    public function actionTeachingTotalUpdate()
    {   
    	// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		

        $manage_id   = (int)$this->get->manage_id;
        $manage_data = $this->db->fetchRow("SELECT * FROM `tbl_manage` WHERE `manage_id`='{$manage_id}' AND `manage_type`='2'");

	    if (empty($manage_data)){
            Helper_Client::alert("文章不存在");
        }

        if ($_POST){ 

            $manage_title     	    = $this->post->manage_title;
            $manage_content   		= $this->post->manage_content;    
                  

            // 写入数据库
            $info = array(
				
			"manage_title"  	    => $manage_title,
            "manage_content"       	=> $manage_content,                      
            "status"                => 1,
            "create_time"           => date("Y-m-d H:i:s"),
            "update_time"           => "0000-00-00 00:00:00",  

			 );

          $this->db->do_update("tbl_manage", $info, "manage_id='{$manage_id}'");

          // 跳转
          Helper_Client::location("修改成功", "index.php?a=teachingtotal.teachingtotallist");

         }

            $this->tpl->assign("manage_data", $manage_data);
	        $this->tpl->display("teaching/total.update.tpl.php");
    } 
	/** 教研计划删除 **/
    public function actionTeachingTotalDel()
    {
        $manage_id = $this->get->manage_id;   
        $this->db->query("DELETE  FROM `tbl_manage` WHERE manage_id='{$manage_id}'");
         // 跳转
        Helper_Client::location("删除成功", "index.php?a=teachingtotal.teachingtotallist");
    }

                           
}

?>